package com.cp.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.Objects;

/**
 * Des:
 *
 * @author cp
 * @Date 2021/9/8 8:13
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {

    private static final long serialVersionUID = -1713428485542357711L;

    /**
     * 状态码
     */
    private int code;
    /**
     * 返回内容
     */
    private String msg;
    /**
     * 数据对象
     */
    private T data;

    /**
     * 拓展参数
     */
    private Object expand;


    public CommonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CommonResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * des:
     * 判断返回结果是成功
     *
     * @return {@link boolean }
     * @author captain
     * @date 2021/9/8 8:16
     */
    public boolean isSuccess() {
        return Objects.equals(this.code, HttpStatus.OK.value());
    }


    /**
     * des:
     * 判断返回结果失败
     *
     * @return {@link boolean }
     * @author captain
     * @date 2021/9/8 8:16
     */
    public boolean isFail() {
        return !this.isSuccess();
    }
}
